package com.cy.login.controller;

import com.comment.util.JwtUtils;
import com.cy.login.comment.core.ResponseResult;
import com.cy.login.domain.Account;
import com.cy.login.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 账号表(Account)表服务控制层
 *
 * @author cxy
 * @since 2024-07-10 15:04:36
 */
@Api(tags = "账号表(Account)") 
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/account")
public class AccountController {
    @Resource
    private final AccountService accountService;
    @ApiOperation("邮箱登录/注册(邮箱和密码必填)")
    @PostMapping("/loginEmail")
    public ResponseResult<Account> loginEmail(@Valid @RequestBody Account account) {
        return ResponseResult.success(accountService.loginEmail(account));
    }
    @ApiOperation("退出登录，请求头必须携带token")
    @PostMapping("/logout")
    public ResponseResult<?> logout(@RequestHeader String token) {
        return ResponseResult.success(accountService.logout(JwtUtils.getUserNameFormJwt(token)));
    }
}
